//! 身份认证与权限服务trait

use async_trait::async_trait;
use crate::{Result, User, Role, Permission};

/// 身份认证与权限服务trait
#[async_trait]
pub trait AuthService: Send + Sync + std::fmt::Debug {
    /// 验证用户凭据
    async fn validate_user(&self, username: &str, password_raw: &str) -> Result<bool>;

    /// 获取用户信息
    async fn get_user(&self, username: &str) -> Result<Option<User>>;

    /// 创建用户
    async fn create_user(&self, user: &User) -> Result<()>;

    /// 删除用户
    async fn delete_user(&self, username: &str) -> Result<()>;

    /// 获取角色信息
    async fn get_role(&self, role_name: &str) -> Result<Option<Role>>;

    /// 创建角色
    async fn create_role(&self, role: &Role) -> Result<()>;

    /// 检查用户是否具有特定权限
    async fn check_permission(&self, username: &str, permission: &Permission) -> Result<bool>;
}
